home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / script-fu / scripts / pupi-button.scm < prev    next >
Encoding:
Text File  |  2003-05-16  |  6.3 KB  |  214 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Round Button --- create a round beveled Web button.
  4. ; Copyright (C) 1998 Federico Mena Quintero & Arturo Espinosa Aldama
  5. ; federico@nuclecu.unam.mx arturo@nuclecu.unam.mx
  6. ; ************************************************************************
  7. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  8. ; For use with GIMP 1.1.
  9. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  10. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  11. ; ************************************************************************
  12. ; This program is free software; you can redistribute it and/or modify
  13. ; it under the terms of the GNU General Public License as published by
  14. ; the Free Software Foundation; either version 2 of the License, or
  15. ; (at your option) any later version.
  16. ; This program is distributed in the hope that it will be useful,
  17. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. ; GNU General Public License for more details.
  20. ; You should have received a copy of the GNU General Public License
  21. ; along with this program; if not, write to the Free Software
  22. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  
  24. (define (text-width extents)
  25.   (car extents))
  26.  
  27. (define (text-height extents)
  28.   (cadr extents))
  29.  
  30. (define (text-ascent extents)
  31.   (caddr extents))
  32.  
  33. (define (text-descent extents)
  34.   (cadr (cddr extents)))
  35.  
  36. (define (round-select img x y width height ratio)
  37.   (let* ((diameter (* ratio height)))
  38.     (gimp-ellipse-select img x y diameter height ADD FALSE 0 0)
  39.     (gimp-ellipse-select img (+ x (- width diameter)) y
  40.              diameter height ADD FALSE 0 0)
  41.     (gimp-rect-select img (+ x (/ diameter 2)) y
  42.               (- width diameter) height ADD FALSE 0)))
  43.   
  44. (define (script-fu-round-button text
  45.                 size
  46.                 font
  47.                 ul-color
  48.                 lr-color
  49.                 text-color
  50.                 ul-color-high
  51.                 lr-color-high
  52.                 hlight-color
  53.                 xpadding
  54.                 ypadding
  55.                 bevel
  56.                 ratio
  57.                 notpressed
  58.                 notpressed-active
  59.                 pressed)
  60.  
  61.   (cond ((eqv? notpressed TRUE)
  62.      (do-pupibutton text size font ul-color lr-color
  63.             text-color xpadding ypadding bevel ratio 0)))
  64.   (cond ((eqv? notpressed-active TRUE)
  65.      (do-pupibutton text size font ul-color-high lr-color-high
  66.             hlight-color xpadding ypadding bevel ratio 0)))
  67.   (cond ((eqv? pressed TRUE)
  68.      (do-pupibutton text size font ul-color-high lr-color-high
  69.             hlight-color xpadding ypadding bevel ratio 1))))
  70.   
  71. (define (do-pupibutton text
  72.                 size
  73.                 font
  74.                 ul-color
  75.                 lr-color
  76.                 text-color
  77.                 xpadding
  78.                 ypadding
  79.                 bevel
  80.                 ratio
  81.                 pressed)
  82.  
  83.   (let* ((old-fg-color (car (gimp-palette-get-foreground)))
  84.      (old-bg-color (car (gimp-palette-get-background)))
  85.      
  86.      (text-extents (gimp-text-get-extents-fontname text
  87.                           size
  88.                           PIXELS
  89.                           font))
  90.      (ascent (text-ascent text-extents))
  91.      (descent (text-descent text-extents))
  92.      
  93.      (height (+ (* 2 (+ ypadding bevel))
  94.             (+ ascent descent)))
  95.  
  96.      (radius (/ (* ratio height) 4))
  97.  
  98.          (width (+ (* 2 (+ radius xpadding))
  99.                    bevel
  100.                    (text-width text-extents)))
  101.  
  102.      (img (car (gimp-image-new width height RGB)))
  103.  
  104.      (bumpmap (car (gimp-layer-new img width height
  105.                        RGBA_IMAGE "Bumpmap" 100 NORMAL)))
  106.      (gradient (car (gimp-layer-new img width height
  107.                     RGBA_IMAGE "Button" 100 NORMAL))))
  108.     (gimp-image-undo-disable img)
  109.  
  110.     ; Create bumpmap layer
  111.     
  112.     (gimp-image-add-layer img bumpmap -1)
  113.     (gimp-selection-none img)
  114.     (gimp-palette-set-background '(0 0 0))
  115.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  116.  
  117.     (round-select img (/ bevel 2) (/ bevel 2)
  118.           (- width bevel) (- height bevel) ratio)
  119.     (gimp-palette-set-background '(255 255 255))
  120.     (gimp-edit-fill bumpmap BG-IMAGE-FILL)
  121.  
  122.     (gimp-selection-none img)
  123.     (plug-in-gauss-rle 1 img bumpmap bevel 1 1)
  124.  
  125.     ; Create gradient layer
  126.  
  127.     (gimp-image-add-layer img gradient -1)
  128.     (gimp-edit-clear gradient)
  129.     (round-select img 0 0 width height ratio)
  130.     (gimp-palette-set-foreground ul-color)
  131.     (gimp-palette-set-background lr-color)
  132.  
  133.     (gimp-blend gradient
  134.         FG-BG-RGB
  135.         NORMAL
  136.         LINEAR
  137.         100
  138.         0
  139.         REPEAT-NONE
  140.         FALSE
  141.         0
  142.         0
  143.         0
  144.         0
  145.         0
  146.         (- height 1))
  147.  
  148.     (gimp-selection-none img)
  149.  
  150.     (plug-in-bump-map 1 img gradient bumpmap
  151.               135 45 bevel 0 0 0 0 TRUE pressed 0)
  152.  
  153. ;     Create text layer
  154.  
  155.     (cond ((eqv? pressed 1) (set! bevel (+ bevel 1))))
  156.  
  157.     (gimp-palette-set-foreground text-color)
  158.     (let ((textl (car (gimp-text-fontname
  159.                img -1 0 0 text 0 TRUE size PIXELS
  160.                font))))
  161.       (gimp-layer-set-offsets textl
  162.                   (+ xpadding radius bevel)
  163.                   (+ ypadding descent bevel)))
  164.  
  165. ;   Delete some fucked-up pixels.
  166.  
  167.     (gimp-selection-none img)
  168.     (round-select img 1 1 (- width 1) (- height 1) ratio)
  169.     (gimp-selection-invert img)
  170.     (gimp-edit-clear gradient)
  171.  
  172. ;     Done
  173.  
  174.     (gimp-image-remove-layer img bumpmap)
  175.     (gimp-image-merge-visible-layers img EXPAND-AS-NECESSARY)
  176.  
  177.     (gimp-selection-none img)
  178.     (gimp-palette-set-foreground old-fg-color)
  179.     (gimp-palette-set-background old-bg-color)
  180.     (gimp-image-undo-enable img)
  181.     (gimp-display-new img)))
  182.  
  183. ; Register!
  184.  
  185. (script-fu-register "script-fu-round-button"
  186.             _"<Toolbox>/Xtns/Script-Fu/Buttons/Round Button..."
  187.             "Round button"
  188.             "Arturo Espinosa (stolen from quartic's beveled button)"
  189.             "Arturo Espinosa & Federico Mena Quintero"
  190.             "June 1998"
  191.             ""
  192.             SF-STRING     _"Text" "The GIMP"
  193.             SF-ADJUSTMENT _"Font Size (pixels)" '(16 2 100 1 1 0 1)
  194.             SF-FONT       _"Font" "-*-helvetica-*-r-*-*-24-*-*-*-p-*-*-*"
  195.             SF-COLOR      _"Upper Color" '(192 192 0)
  196.             SF-COLOR      _"Lower Color" '(128 108 0)
  197.             SF-COLOR      _"Text Color" '(0 0 0)
  198.             SF-COLOR      _"Upper Color (Active)" '(255 255 0)
  199.             SF-COLOR      _"Lower Color (Active)" '(128 108 0)
  200.             SF-COLOR      _"Text Color (Active)" '(0 0 192)
  201.             SF-ADJUSTMENT _"Padding X" '(4 0 100 1 10 0 1)
  202.             SF-ADJUSTMENT _"Padding Y" '(4 0 100 1 10 0 1)
  203.             SF-ADJUSTMENT _"Bevel Width" '(2 0 100 1 10 0 1)
  204.             SF-ADJUSTMENT _"Round Ratio" '(1 0.05 20 0.05 1 2 1)
  205.             SF-TOGGLE     _"Not Pressed" TRUE
  206.             SF-TOGGLE     _"Not Pressed (Active)" TRUE
  207.             SF-TOGGLE     _"Pressed" TRUE)
  208.  
  209.  
  210.